<?php
	$this->headTitle($this->translator('assignment_view_page_title'));
	$this->headScript()
        ->appendFile($this->APP_STATIC_SERVER . '/js/jquery.tools/jquery.tools.js');
?>
<?php if($this->isAllowAction):?>
<style>
	table{
		border-top:none;
		border-bottom:none;
		}
	.list table{
		width: 100%;
		border-top: 0px;
		border-bottom: 0px;
	}
	.list .caption td{
		font-weight: bold;
		background: #BCBBB9;
	}
	.list tr.caption:hover td{
		font-weight: bold;
		background: #BCBBB9;
	}
	.list tbody tr:hover td{
		background: #EFEDED;
	}
	.inline_block{
		display: inline-block;
		width: 100%;
	}
	.inline_block .col_33{
		float:left;
		width:33.3%;
	}
	.inline_block .col_33 input{
		cursor: pointer;
	}
	.clear_fix{
		clear: both;
	}
	.cart_bottom{
		margin-bottom: 10px;
	}
	.cart .amount div label{
		font-weight: bold;
	}
	.tooltip {
		display:none;
		background:#BCBBB9;
		height:auto;
		width:200px;
		padding:10px;
	} 	
</style>
<div class="grid_12">
    <div class="icon_title">
		<span>
			<?php echo $this->translator('customer_order_detail');?>			
		</span>		
	</div>
    <hr style="padding:0;"/>
    <!--div class="grid_12"><?php // echo $this->flashMessenger(); ?></div-->
    <?php
        /**
        * Order info
        **/
        $order = $this->order;

        /**
        * Current user
        **/
        $user = $this->user;

        /**
         * Order currency
        **/
        $currency = ($order->order_modify_amount_currency)?$order->order_modify_amount_currency:$order->order_total_amount_currency;
    ?>
    <div class="grid_12 t_a_bottom">
        <div style="margin-left:20px;">
            <div class="clearfix t_a_bottom" style="font-size:12px;margin-bottom:10px;">
                <div class="grid_3 alpha">					
                    <label><?php echo $this->translator('customer_order_invoice'); ?>:</label>
                    <span><b><?php echo ($order->order_invoice)?$order->order_invoice:'-';?></b></span>
                </div>				
                <div class="grid_3 omega">
                    <label><?php echo $this->translator('customer_order_date_created'); ?>:</label>
                    <span><b><?php echo date('d-m-Y',strtotime($order->order_created_date));?></b></span>
                </div>
                <div class="grid_3 omega">
					<?php 						
						$conn = Tomato_Db_Connection::factory()->getMasterConnection();
						$enterpriseDao = Tomato_Model_Dao_Factory::getInstance()->setModule('enterprise')->getEnterpriseDao();
						$enterpriseDao->setDbConnection($conn);
						$enterprise = $enterpriseDao->getById($order->enterprise_id);	
						$arrayEnterpriseInfo = $enterprise;						 
						$arrRouteDetail = array(
							'enterprise_id' => $enterprise->id,
							'enterprise_name' => Tomato_Utility_String::removeSign($enterprise->company_name_en, '-', true),
						);						
					?>										
                    <label><?php echo $this->translator('customer_enterprise_name'); ?>:</label>
                    <a href="<?php echo $this->url($arrRouteDetail,'bizprofile_enterprise_index')?>"><span><b><?php echo $enterprise->company_name_en;?></b></span></a>
                </div>
            </div>
        </div>
    </div>    
</div>
	<div class="grid_12">
		<div class="grid_9 alpha">
			<!--Order detail list-->
			<div class="icon_title" style="width:60%;"><span><?php echo $this->translator('customer_order_detail_list');?></span></div>
			<div style="float:right;text-align:right;margin-bottom:-10px;">
                    <label><?php echo $this->translator('customer_order_subtotal'); ?>:</label>
                    <span>
						<b>
						<?php echo ($order->order_modify_amount)?$order->order_modify_amount:$order->order_total_amount;?>&nbsp;<?php echo $currency;?>
						</b>
					</span>
					<br/>
                    <label><?php echo $this->translator('customer_order_shipping_price'); ?>:</label>
                    <span>
						<b>
						<?php echo $order->order_total_shipping_price;?>&nbsp;<?php echo $currency;?>
						</b>
					</span>				
			</div>
			<hr/>	
			<table class="list" style="width:100%;">
				<tr class="caption">
					<td width="40%"><?php echo $this->translator('order_product_name', 'shop');?></td>
					<td width="35%"><?php echo $this->translator('order_values', 'shop');?></td>
					<td width="10%"><?php echo $this->translator('order_quantity', 'shop');?></td>
					<td width="15%"><?php echo $this->translator('order_amount', 'shop');?></td>
				</tr>
				<?php if(count($this->orderDetails) > 0):?>
				<?php foreach ($this->orderDetails as $row):?>
				<?php
					/**
					* Attribute and value info
					**/
					$attValue = isset($this->arrAllAtVal[$row->order_detail_id])?$this->arrAllAtVal[$row->order_detail_id]:'-';

					/**
					 * Product info to view
					**/
					$arrProducts = $this->arrProducts[$row->order_detail_id];
				?>
				<tr>
		 		<td><?php echo $arrProducts;?></td>
					<td><?php echo $attValue;?></td>
					<td><?php echo $row->order_detail_quantity;?></td>
					<td><?php echo $row->order_detail_quantity*$row->order_detail_product_price;?> <?php echo $row->order_detail_currency;?></td>
				</tr>
				<?php endforeach;?>
				<?php endif;?>
			</table>				
			<div class="grid_9 alpha">
				<div class=" icon_title" style="width:50%;float:left;">
					<span>
						<?php echo $this->translator('cart_payment_method');?>
						:	
					</span>					 	
					<?php if($order->payment_method =="bank_transfer"):?>
					<span style=" float: left;font-size: 12px;padding: 12px 5px 5px;text-transform: none;font-weight: normal;">
						<?php echo $this->translator('cart_payment_bank');?>
					</span>
					<?php endif;?>
					<?php if($order->payment_method =="cash"):?>
					<span style=" float: left;font-size: 12px;padding: 12px 5px 5px;text-transform: none;font-weight: normal;">
						<?php echo $this->translator('cart_payment_cash');?>
					</span>
					<?php endif;?>
					<hr style="padding:0;"/>
				</div>
			</div>
			<?php if($order->payment_method =="cash"):?>			
			<div style="margin-left:20px;">				
				<div>
					<label><?php echo $this->translator('cart_contact_email')?></label>:
					<?php echo $arrayEnterpriseInfo->contact_email;?>
				</div>
				<div>
					<label><?php echo $this->translator('cart_contact_tel')?></label>:
					<?php echo $arrayEnterpriseInfo->contact_tel;?>
				</div>
				<div>
					<label><?php echo $this->translator('cart_contact_fax')?></label>:
					<?php echo $arrayEnterpriseInfo->contact_fax;?>
				</div>
				<div>
					<label><?php echo $this->translator('cart_contact_address')?></label>:
					<?php echo $arrayEnterpriseInfo->contact_address;?>
				</div>
				<div>
					<label><?php echo $this->translator('cart_currency')?></label>:
					<?php echo $arrayEnterpriseInfo->currency;?>
				</div>
			</div>
			<?php endif;?>
			<?php if($order->payment_method =="bank_transfer"):?>
					<div style="margin-left:20px;">
						<div><?php echo $this->translator('cart_enterprise_account');?> VND</div>
						<hr/>
						<div>
							<label><?php echo $this->translator('cart_bank_name')?></label>:
							<?php echo $arrayEnterpriseInfo->bank_name_vnd;?>
						</div>
						<div>
							<label><?php echo $this->translator('cart_bank_account')?></label>:
							<?php echo $arrayEnterpriseInfo->bank_account_vnd;?>
						</div>
						<div>
							<label><?php echo $this->translator('cart_bank_account_owner')?></label>:
							<?php echo $arrayEnterpriseInfo->bank_account_owner_vnd;?>
						</div>

						<div class="cart_bottom"></div>

						<div><?php echo $this->translator('cart_enterprise_account');?> USD</div>
						<hr/>
						<div>
							<label><?php echo $this->translator('cart_bank_name')?></label>:
							<?php echo $arrayEnterpriseInfo->bank_name_usd;?>
						</div>
						<div>
							<label><?php echo $this->translator('cart_bank_account')?></label>:
							<?php echo $arrayEnterpriseInfo->bank_account_usd;?>
						</div>
						<div>
							<label><?php echo $this->translator('cart_bank_account_owner')?></label>:
							<?php echo $arrayEnterpriseInfo->bank_account_owner_usd;?>
						</div>
					</div>			
			<?php endif;?>
			<!--End order detail list-->
		</div>
		<div class="grid_3" style="margin:0;width:250px;">
			<!--Tracking history-->
			<div class="icon_title"><span><?php echo $this->translator('customer_order_tracking_label');?></span></div>	
			<hr/>
			<div class="flash_message"><?php echo $this->flashMessenger(); ?></div>
			<div class="clearfix t_a_bottom" style="margin-bottom: 5px;padding-left:5px;">
				<label><?php echo $this->translator('order_actual_tracking_status', 'shop'); ?>:</label>
				<span><b><?php echo (trim($this->status))?$this->translator('order_tracking_status_'.$this->status, 'shop'):'-';?></b></span>
			</div>			
				<?php if(strstr($this->strRoleId, ','.$this->user->role_id.',')):?>
				<!--begin form-->
				<div style="margin-left:5px;">
					<form method="post" action="" id="editTrackingForm">    
						<div class="clearfix t_a_bottom">
							<div>
								<div style="float:right">	
								<?php if(count($this->arrSteps) > 1):?>
									<select style="width:120px;" name="process_id" >
										<?php foreach($this->arrSteps as $key=>$step):?>
										<?php if(strstr($step->performer_role_id_chain,','.$user->role_id.',')):?>
										<option value="<?php echo $this->arrProcess[$key];?>"><?php echo $this->translator('order_tracking_step_'.$step->code, 'shop');?></option>
										<?php endif;?>
										<?php endforeach;?>
									</select>							
								<?php else:?>
									<?php foreach($this->arrSteps as $key=>$step):?>
										<?php if(strstr($step->performer_role_id_chain,','.$user->role_id.',')):?>
										<?php echo $this->translator('order_tracking_step_'.$step->code, 'shop');?>
										<input type="hidden" value="<?php echo $this->arrProcess[$key];?>" name="process_id" />
										<?php endif;?>
									<?php endforeach;?>
								<?php endif;?>
								</div>
								<label><?php echo $this->translator('order_new_tracking_status', 'shop'); ?>:</label>		
								<br/>	
								<textarea name="order_tracking_remark" rows="4" style="width:100%;margin-top:3px;"></textarea>
								<div style="float:left;margin-left:3px;margin-top:3px;">
									<button type="submit"><span style="height:30px; text-align:center; width:auto;" ><?php echo $this->translator('tracking_save_button', 'shop');?></span></button>
								</div>
							</div>
						</div>
					</form>
				</div>
				<!-- end form -->			
				<?php else:?>
				<!--Evaluation-->
					<?php if($this->allow('evaluation')):?>
						<?php if($this->status == 'finished'):?>
						<div>
							<div style="margin-bottom: 5px;">
								<div>
									<label style="font-weight:bold;"><?php echo $this->translator('customer_view_evaluation_by_buyer'); ?>:</label>
								</div>
								<div style="margin-left:5px;">		
									<?php if($this->orderEval && null != $this->orderEval->buyer_user_id):?>
										<div>
											<label style="width:80px;"><?php echo $this->translator('order_view_point', 'shop');?>:</label>
											<span><?php echo $this->orderEval->buyer_to_seller_evaluation;?></span>
										</div>																
										<div>
											<label style="width:80px;"><?php echo $this->translator('order_view_evaluation', 'shop');?>:</label>
											<span><?php echo $this->orderEval->buyer_to_seller_feedback;?></span>
										</div>								
									<?php else:?>
										<?php if($this->bEvaluated):?>
										<form action="<?php echo $this->url(array(), 'customer_customer_evaluation')?>" method="POST" id="sellerEvaluationForm">
											<input type="hidden" value="<?php echo (null != @$this->orderEval->seller_user_id)?true:false;?>" name="update" />
											<input type="hidden" value="<?php echo $this->bEvaluated;?>" name="bEvaluated" />
											<input type="hidden" value="<?php echo $this->order->order_id;?>" name="order_id" />
											<input type="hidden" value="<?php echo $this->user_enterprise;?>" name="enterprise_id" />
											<input type="hidden" value="<?php echo $this->user->user_id;?>" name="buyer_id" />
											<input type="hidden" value="<?php echo $this->order->enterprise_id;?>" name="eval_enterprise_id" />
											<div>
												<label style="width:80px;"><?php echo $this->translator('order_view_point', 'shop');?>:</label>
												<select name="point" style="width:50px">
													<?php for($n=1;$n<=10;$n++):?>
													<option value="<?php echo $n;?>"><?php echo $n;?></option>
													<?php endfor;?>
												</select>
											</div>
											<div>
												<label style="width:80px;"><?php echo $this->translator('order_view_evaluation', 'shop');?>:</label>
												<textarea name="evaluation" style="width:250px; height:50px"></textarea>
											</div>
											<div style="margin-top:3px;">
												<label style="width:80px;">&nbsp;</label>
												<button type="submit"><span style="height:30px; text-align:center; width:auto;" ><?php echo $this->translator('order_rating_save_button','shop');?></span></button>
											</div>
										</form>
										<?php else:?>										
										<div><?php echo $this->translator('order_buyer_no_evaluate_yet', 'shop');?></div>
										<?php endif;?>
									<?php endif;?>																							
								</div>	
							</div>
							<div>
								<div>
									<label style="font-weight:bold;"><?php echo $this->translator('order_view_rating_seller', 'shop'); ?>:</label>									
								</div>
								<div style="margin-left:5px;">	
									<?php if($this->orderEval && null != $this->orderEval->seller_user_id):?>							
									<div>
										<label style="width:80px;"><?php echo $this->translator('order_view_point', 'shop');?>:</label>
										<span><?php echo $this->orderEval->seller_to_buyer_evaluation;?></span>
									</div>
									<div>
										<label style="width:80px;"><?php echo $this->translator('order_view_evaluation', 'shop');?>:</label>
										<span><?php echo $this->orderEval->seller_to_buyer_feedback;?></span>
									</div>								
									<?php else:?>
										<div><?php echo $this->translator('order_seller_no_evaluate_yet', 'shop');?></div>
										<!--<?php if($this->sEvaluated):?>
										<form action="<?php echo $this->url(array(), 'customer_customer_evaluation')?>" method="POST" id="sellerEvaluationForm">
											<input type="hidden" value="<?php echo (null != @$this->orderEval->buyer_user_id)?true:false;?>" name="update" />
											<input type="hidden" value="<?php echo $this->sEvaluated;?>" name="sEvaluated" />
											<input type="hidden" value="<?php echo $this->order->order_id;?>" name="order_id" />
											<input type="hidden" value="<?php echo $this->user_enterprise;?>" name="enterprise_id" />
											<input type="hidden" value="<?php echo $this->user->user_id;?>" name="seller_id" />
											<input type="hidden" value="<?php echo $this->order->customer_id;?>" name="customer_id" />
											<div>
												<label style="width:80px;"><?php echo $this->translator('order_view_point','shop');?>:</label>
												<select name="point" style="width:50px">
													<?php for($n=1;$n<=10;$n++):?>
													<option value="<?php echo $n;?>"><?php echo $n;?></option>
													<?php endfor;?>
												</select>
											</div>
											<div>
												<label style="width:80px;"><?php echo $this->translator('order_view_evaluation', 'shop');?>:</label>
												<textarea name="evaluation" style="width:250px; height:50px"></textarea>
											</div>
											<div style="margin-top:3px;">
												<label style="width:80px;">&nbsp;</label>
												<button type="submit"><span style="height:30px; text-align:center; width:auto;" ><?php echo $this->translator('order_rating_save_button', 'shop');?></span></button>
											</div>
										</form>
										<?php else:?>
											<div><?php echo $this->translator('order_seller_no_evaluate_yet', 'shop');?></div>
										<?php endif;?>-->										
									<?php endif;?>								
								</div>
							</div>
						</div>
						<?php endif;?>
					<?php endif;?>
					<!--End evaluation-->				
				<?php endif;?>
			<div class="icon_title"><span><?php echo $this->translator('customer_order_tracking_history');?></span></div>	
			<table class="list" style="width:100%;">
				<tr class="caption">
					<td width="50%"><?php echo $this->translator('order_edit_tracking_status', 'shop');?></td>					
					<td width="50%">&nbsp;</td>
				</tr>
				<?php
					$trackings = $this->trackings
				?>
				<?php if(count($trackings) > 0):?>
				<?php foreach($trackings as $index=>$tracking):?>
				<?php
					/**
					* Tracking cost
					**/
					$order_tracking_cost = ($tracking->order_tracking_cost > 0)?$tracking->order_tracking_cost:'-';

					/**
					* Status
					**/
					$status = isset($this->arrStatus[$tracking->order_tracking_id])?$this->translator('order_tracking_status_'.$this->arrStatus[$tracking->order_tracking_id],'shop'):'-';
				?>
				<tr>
					<td>
						<i><?php echo ($tracking->order_tracking_date)?date('d-m-Y',strtotime($tracking->order_tracking_date)):'-';?></i>
						<br/>
						<?php echo $status;?>
					</td>
					<td width="50%;" style="text-align:justify;">
						<?php echo trim($tracking->order_tracking_remark)?$tracking->order_tracking_remark:'-'?>					
					</td>					
				</tr>
				<?php endforeach;?>
				<?php endif;?>
			</table>			
			<!--End tracking history-->
		</div>
	</div>
<div id="messageDialog"></div>
<div id="confirmDialog"></div>

<script type="text/javascript">
$(document).ready(function() {
});
</script>
<?php else:?>
    <div class="grid_12"><?php echo $this->translator('customer_no_permission');?></div>
<?php endif;?>